package com.k.Intercept;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

public class UserRoleCheck extends HibernateDaoSupport implements UserRoleCheckImport{

	public Boolean findByHql(final String ServiceClass,final String ServiceMethod,final Integer Roleid) {  
		
		
		//return this.getHibernateTemplate().find("from SRolefunction").size()>0;
		return this.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session)
			throws HibernateException, SQLException {
				String hql="from SRolefunction r,SFunction f where r.functionid=f.id and r.roleid=:Roleid and f.SServiceClass=:ServiceClass and f.SServiceMethod=:ServiceMethod";
				Query query = session.createQuery(hql);
				Map<Serializable, Serializable> map=new HashMap();
				map.put("Roleid", Roleid);
				map.put("ServiceClass", ServiceClass);
				map.put("ServiceMethod", ServiceMethod);
				for (Serializable key : map.keySet()) {
					query.setParameter((String) key, map.get(key));
				}
		query.setFirstResult(0);
		query.setMaxResults(1);
		Object obj = query.uniqueResult();
		if(obj==null)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
});  
	} 
}
